package UDP.Client;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

public class Client {
    public static void main(String[] args) throws Exception {
        DatagramSocket socket = new DatagramSocket();
        socket.setSoTimeout(1000);
        socket.connect(InetAddress.getByName("127.0.0.1"),8888);


        byte[] buf = "Hello World".getBytes();
        DatagramPacket packet = new DatagramPacket(buf, buf.length);
        socket.send(packet);

        byte[] buffer = new byte[1024];
        DatagramPacket receivedPacket = new DatagramPacket(buffer, buffer.length);
        socket.receive(receivedPacket);
        String received = new String(receivedPacket.getData());
        System.out.println(received);
        socket.disconnect();
        socket.close();



    }
}
